;;;   -*- Syntax: Common-Lisp; Package: USER; Base: 10; Mode: LISP -*-    ;;;
;;;                                                                       ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Each fold  contains a variable and its associated accessors and
;;; modifiers.
;;; Only the modifiers exported. 
;;; Contains all defvars etc used by afl.
;;; Also contains accessor and modifiers for these defvars.
;;; { *list-of-dimensions*
;;; Variable: *LIST-OF-DIMENSIONS*                           Author: raman
;;; Created: Sat Aug  8 15:35:18 1992
;;; This function pushes the name on to the the global list of
;;; dimensions, and will later also set up the global values etc. Will
;;; possibly generate a defstruct for defining the point in speech
;;; space. Hold this off until second pass.
;;; Modified: Tue Aug 18 12:20:31 EDT 1992
;;; added call to rearrange-dimensions-for-dectalk inside this
;;; function.
;;; Function: ADD-DIMENSION                                  Author: raman
;;; Created: Sat Aug  8 15:45:51 1992
;;; }
;;; { *global-values*
;;;  comments on global settings implementation
;;; *global-values* holds the global settings of parameters in the
;;; speech space.  It is a hashtable, and has an 
;;; entry  associated with each dimension in the speech space,
;;; and the value assigned to it is of type reference, a structure
;;; that implements indirection.
;;; global will be automatically defined by the user defining
;;; the speech space. Provide set of macros for defining speech space
;;; abstractly once the first pass of the afl-language is done.
;;; The function setup-globals sets up global settings base don the
;;; dimensions defined. etc. 
;;; currently global settings are stored in a hash table.
;;; 
;;; Variable: *GLOBAL-VALUES*                              Author: raman
;;; Created: Fri Aug  7 12:46:20 1992
;;; 
;;;  Function: DEFINE-GLOBAL-VALUE Author: raman
;;; Created: Fri Aug  7 12:49:30 1992
;;; 
;;; Function: GET-GLOBAL-VALUE                                  Author: raman
;;; Created: Fri Aug  7 13:29:55 1992
;;; }
;;; { *table-of-units*
;;; implements tables for holding  information about speech space and
;;; how to manipulate it.
;;; For each slot in the structure point-in-speech-space there is a
;;; table that holds the dimension value pair for that slot. For the
;;; value slot, this is the same as the *global-values* defined in
;;; 01-speech-space.lisp  The tables implemented in this file need not
;;; to be known to global-set, which is why they reside here.
;;; in addition unit-size and synthesizer-code which are not expected
;;; to change during a program are also kept in tables here, and their
;;; associated fields do not appear in the structure dimension.
;;; All tables are implemented as hash tables for the present.  May
;;; change later:
;;; Variable: *TABLE-OF-UNITS*                               Author: raman
;;; Created: Fri Aug  7 17:49:29 1992
;;; Function: DEFINE-UNIT-SIZE                               Author: raman
;;; Created: Fri Aug  7 17:51:13 1992
;;; Function: GET-UNIT-SIZE                                  Author: raman
;;; Created: Fri Aug  7 17:52:43 1992
;;; }
;;; {*table-of-synthesizer-codes*
;;; Variable: *TABLE-OF-SYNTHESIZER-CODES* Author: raman
;;; Created: Fri Aug  7 17:49:29 1992
;;; Function: DEFINE-SYNTHESIZER-CODE Author: raman
;;; Created: Fri Aug  7 17:51:13 1992
;;; Function: GET-SYNTHESIZER-CODE Author: raman
;;; Created: Fri Aug  7 17:52:43 1992
;;; }
;;; { *table-of-step-sizes*
;;; Variable: *TABLE-OF-STEP-SIZES* Author: raman
;;; Created: Fri Aug  7 17:49:29 1992
;;; Function: DEFINE-STEP-SIZE                               Author: raman
;;; Created: Fri Aug  7 17:51:13 1992
;;; Function: GET-STEP-SIZE                                  Author: raman
;;; Created: Fri Aug  7 17:52:43 1992
;;; }
;;; { *standard-voices*
;;; standard voices stored in a table.
;;; this is a hash table which for each name holds the point in speech
;;; space for that voice.
;;; Variable: *STANDARD-VOICES*                              Author: raman
;;; Created: Sat Aug  8 09:24:43 1992
;;; Modified: Tue Aug 11 10:09:32 EDT 1992
;;; Function: DEFINE-DISTINGUISHED-POINT                     Author: raman
;;; Created: Sun Aug  9 15:52:02 1992
;;; Function: DEFINE-STANDARD-VOICE                          Author: raman
;;; Created: Sat Aug  8 09:36:28 1992
;;; Function: GET-STANDARD-VOICE Author: raman
;;; Created: Sat Aug  8 09:30:57 1992
;;; }
;;;   -*- Syntax: Common-Lisp; Package: USER; Base: 10; Mode: LISP -*-    ;;;
;;;                                                                       ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; implements reference variables. Uses a mutable object structure
;;; with one field val. A method reference-value is written to make
;;; the interface clean. If passed any lisp object reference-value
;;; returns it, except for objects of type reference in which case the
;;; slot value is returned.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; { Structure: REFERENCE                                     Author: raman
;;; Created: Fri Aug  7 11:27:54 1992
;;; A mutable object that implements reference variables
;;; }
;;; { method reference-value
;;; Overloading reference-value. If argument is not a reference
;;; object, just return it, otherwise return the slot value.
;;; Method: REFERENCE-VALUE                                  Author: raman
;;; Created: Fri Aug  7 11:44:54 1992
;;; Method: REFERENCE-VALUE                                  Author: raman
;;; Created: Fri Aug  7 11:48:37 1992
;;; }
;;; This function is taken from Norvig's book.
;;; It is useful for building up function names etc.
;;; 
;;;   -*- Syntax: Common-Lisp; Package: USER; Base: 10; Mode: LISP -*-    ;;;
;;;                                                                       ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Each fold contains functions associated with the fold marker
;;; { Introduction:
;;; This file contains definitions of points in the speech space.
;;; Points in the speech space are currently implemented as
;;; structures. A point in the speech space determines the parameter
;;; values along the various dimensions defining the space. Dimensions
;;; include head-size, breathiness, voice, volume etc.  The information
;;; pertinent to each dimension is captured in a structure called
;;; dimension.  Relevant information includes name of the dimension,
;;; value, default step size.
;;; the structure dimension captures those bits of information that
;;; are liable to change, eg: value, step-size. Synthesizer code will
;;; not change for a dimension during the program, so this is kept
;;; separately in a hash table. 
;;;
;;; The point in speech space will contain fields each of which will
;;; be assigned an object of type dimension encapsulating the current
;;; settings along that dimension.
;;; The structure for points in speech space is automatically
;;; generated from the list of dimensions specified by the user. 
;;; Global values are stored in a special structure that implements
;;; reference variables.  
;;; The dimensions in the speech space are first captured in a list
;;; called *list-of-dimensions* and this is used by all the functions.
;;; The structure definition for point-in-speech-space is
;;; generated from this list by a macro. 
;;;
;;; }
;;; { dimension
;;;  Structure: DIMENSION                                     Author: raman
;;; note: the dimension voice is in a sense redundant. The other
;;; dimensions that occur in the speech space are independent of one
;;; another, they together determine the voice.
;;; Structure:  dimension Author: raman
;;; Created: Fri Aug  7 10:25:35 1992
;;; A dimension in speech space. 
;;; 
;;; function create-dimension takes a name and creates a structure of
;;; type dimension with the values set to their initial defaults. It
;;; does this by doing a table look up for the various fields.
;;; Modified: Tue Aug 18 14:41:37 EDT 1992
;;; Dereference global values if used as defaults when creating a new
;;; dimension. 
;;; Function: CREATE-DIMENSION                               Author: raman
;;; Created: Fri Aug  7 18:10:21 1992
;;; Adding accessor table to allow for setf form for
;;; dimension-accessor.  This is because I need to modify slots in the
;;; dimension structure in the move operators by supplying a slot
;;; name.
;;; Variable: *DIMENSION-ACCESSOR-TABLE*                     Author: raman
;;; Created: Wed Aug 19 09:02:51 1992
;;; Function: DIMENSION-ACCESSOR                             Author: raman
;;; Created: Wed Aug 19 09:09:20 1992
;;; DEFSETF form for modifying slots in dimension:
;;; }
;;; { point-in-speech-space 
;;; point-in-speech-space a structure: 
;;; this is  generated automatically from the list of
;;; dimensions. 
;;; point in speech space
;;; The following function relies on the list representation of the
;;; structure point-in-speech-space and will have to be changed if the
;;; structure representation for points in speech space is modified. 
;;; Function: UPDATE-POINT-IN-SPEECH-SPACE Author: raman
;;; Created: Sun Aug  9 18:04:02 1992
;;; Following function relies on the
;;; list representation of point-in-speech-space
;;; Function: POINT-ACCESSOR                                 Author: raman
;;; Created: Sat Aug 15 09:10:28 1992
;;; Modified: Tue Aug 11 09:52:58 EDT 1992
;;; Made to work using *list-of-dimensions*
;;; defsetf form for updating points
;;; Could be sued as an alternative to update-point-in-speech-space
;;; Also relies on the list representation of point-in-speech-space
;;; Usage:
;;; (setf (point-accessor dimension point) value) 
;;; Modified: Tue Aug 18 15:55:04 EDT 1992
;;; creates a point in the speech space at global scope, ie: global
;;; sets will affect the settings of this point. To be used by the
;;; function that initializes the speech space.
;;; Function: CREATE-initial-POINT-IN-SPEECH-SPACE                   Author: raman
;;; Created: Fri Aug  7 18:18:07 1992
;;; Function: EMBED-POINT-IN-SPEECH-SPACE                Author: raman
;;; Created: Wed Aug 12 10:24:38 1992
;;; }
;;; { initialize-speech-space 
;;; comments on initializing speech space:
;;; initializing speech space will include the following steps:
;;; Do a table lookup and get the values for the default voice
;;; specified by the user. Store associated values in the
;;; *global-values* so that global-set can manipulate it. Construct
;;; a point in speech space which is the origin and set current-state
;;; to this point.
;;;
;;; How this will be implemented:
;;; initialize-speech-space takes an optional argument a voice-name.
;;; It then looks up the default values for this voice. These are then
;;; entered into the various tables. Thus when this function finishes
;;; its work, we have the default settings as well as a start point.
;;; Function: INITIALIZE-SPEECH-SPACE                        Author: raman
;;; Created: Fri Aug  7 12:44:56 1992
;;; Function: SETUP-GLOBALS                                  Author: raman
;;; Created: Sat Aug  8 10:15:54 1992
;;; Function: DEFINE-GLOBALS                                 Author: raman
;;; Created: Sat Aug  8 11:10:29 1992
;;; }
;;; { rearrange-dimensions-for-dectalk
;;; This function resets *list-of-dimensions* after rearranging the
;;; dimensions in the right order for dectalk.  The only thing that
;;; matters is that the voice if present be placed in front of the
;;; list.
;;; Function: REARRANGE-DIMENSIONS-FOR-DECTALK               Author: raman
;;; Created: Sun Aug 16 12:33:28 1992
;;; }
;;;   -*- Syntax: Common-Lisp; Package: USER; Base: 10; Mode: LISP -*-    ;;;
;;;                                                                       ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; export all dimension names. 
;;; This file has the user definition of speech space, ie: set up list
;;; of dimensions, specify default values etc. 
;;; Each fold contains assignments to one global table
;;; { *list-of-dimensions*
;;; First initialize by setting list of dimensions to nil
;;; At present for the dectalk the order in which dimensions are added
;;; is important.  I will need to fix this. The problem is that the
;;; voice dimension has to be set first on the dectalk as setting this
;;; after setting something else clobbers earlier settings.
;;; }
;;; { define-synthesizer-code
;;; defining some synthesizer codes. dectalk specific
;;; }
;;; { define-global-value 
;;; Some default values
;;; }
;;; { define-step-size
;;; define global step sizes
;;; }
;;; { define-unit-size
;;; }
;;;   -*- Syntax: Common-Lisp; Package: USER; Base: 10; Mode: LISP -*-    ;;;
;;;                                                                       ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; rearrange dimensions for dectalk:
;;; first define points in speech space
;;; Export all dimension names
;;; This file defines the standard voices as points in the speech
;;; space using the function define-standard-voice
;;; set up standard voices. 
;;;   -*- Syntax: Common-Lisp; Package: USER; Base: 10; Mode: LISP -*-    ;;;
;;;                                                                       ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Implements the move operators as discussed in the notes on audio
;;; formatting primitives.
;;; Refer to: <(notes on audio formatting)>
;;; The operators return points in speech space. There are four move operators.
;;; Each fold contains  an operator
;;; { move-by 
;;; Modified: Wed Aug 19 08:50:02 EDT 1992
;;; Adding keyword argument slot with default value
;;; 'value   so that by default move operators change the
;;; value slot. Having this keyword argument allows the program to
;;; cleanly modify step size if necessary by specifying  :slot
;;; 'step-size
;;; Function: MOVE-BY                                        Author: raman
;;; Created: Sun Aug  9 15:55:50 1992
;;; }
;;; { step-by 
;;; Modified: Wed Aug 19 09:23:37 EDT 1992
;;; added keyword argument :slot with default 'value
;;; Doing this to maintain consistency with the other move operators,
;;; it does not make too much sense to call step-by with :slot 'step-size
;;; Function: STEP-BY                                           Author: raman
;;; Created: Sun Aug  9 17:48:50 1992
;;; }
;;; {move-to 
;;; Modified: Wed Aug 19 09:27:20 EDT 1992
;;; Added keyword argument :slot with default 'value
;;; Function: MOVE-TO                                        Author: raman
;;; Created: Sun Aug  9 17:53:36 1992
;;; }
;;; {scale-by
;;; Modified: Wed Aug 19 09:28:23 EDT 1992
;;;; Added keyword argument :slot with default 'value
;;; Function: SCALE-BY                                          Author: raman
;;; Created: Sun Aug  9 17:56:53 1992
;;; }
;;; { multi-move-by
;;; Function: MULTI-MOVE-BY                                  Author: raman
;;; Created: Wed Aug 12 09:49:55 1992
;;; }
;;; { multi-move-to
;;; Function: MULTI-MOVE-TO                                  Author: raman
;;; Created: Wed Aug 12 09:56:09 1992
;;; }
;;; { multi-scale-by
;;; Function: MULTI-SCALE-BY                                 Author: raman
;;; Created: Wed Aug 12 09:57:31 1992
;;; }
;;; { multi-step-by
;;; Function: MULTI-STEP-BY                                  Author: raman
;;; Created: Wed Aug 12 09:58:30 1992
;;; }
;;;   -*- Syntax: Common-Lisp; Package: USER; Base: 10; Mode: LISP -*-    ;;;
;;;                                                                       ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;  Contains definition of new-block as a macro.
;;; and associated assignment operators.
;;; { *current-state*
;;; Variable: *CURRENT-STATE*                                Author: raman
;;; Created: Fri Aug 14 10:29:11 1992
;;; }
;;; { new-block
;;; Macro: NEW-BLOCK                                         Author: raman
;;; Created: Mon Aug 10 12:57:43 1992
    ;;; reset state 
;;; }
;;; { assignments
;;; This function assumes the list representation of the
;;; structure point-in-speech-space 
;;; Function: SET-STATE                                      Author: raman
;;; Created: Mon Aug 10 13:43:53 1992
;;; Macro: LOCAL-SET!                                     Author: raman
;;; Created: Mon Aug 10 13:45:45 1992
;;; Modified: Thu Aug 13 17:56:17 EDT 1992
;;; pass current state as an argument to global-set! as using a free
;;; variable causes unexpected results when called in conjunction with
;;; new-block which is a macro. 
;;; Function: GLOBAL-SET!                                    Author: raman
;;; Created: Fri Aug  7 14:29:19 1992
;;; It does not make sense to just set 'voice globally, if a global
;;; change in voice is desired, the speech space has to be
;;; initialized.
  (set-state  state) ; actually send the commands.
;;; }
;;;   -*- Syntax: Common-Lisp; Package: USER; Base: 10; Mode: LISP -*-    ;;;
;;;                                                                       ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Initially assumes dectalk, but to be flexible enough to allow any
;;; synthesizer.
;;; { Start and end markers 
;;; Variable: *BEGIN-COMMAND*                                Author: raman
;;; Created: Tue Aug 11 13:40:16 1992
;;; Variable: *END-COMMAND*                                  Author: raman
;;; Created: Tue Aug 11 13:40:44 1992
;;; }
;;; { generate-synthesizer-command
;;; Function: GENERATE-SYNTHESIZER-COMMAND                   Author: raman
;;; Created: Tue Aug 11 13:41:18 1992
;;; }
;;; { *voice-codes-table*
;;; Variable: *VOICE-CODES-TABLE*                            Author: raman
;;; Created: Tue Aug 11 14:56:19 1992
;;; Structure: VOICE-CODE                                    Author: raman
;;; Created: Tue Aug 11 14:58:10 1992
;;; Function:  DEFINE-VOICE-CODE Author: raman Created: Tue Aug 11 14:56:56 1992
;;; Function: GET-VOICE-CODE                                 Author: raman
;;; Created: Tue Aug 11 15:03:42 1992
;;; }
;;;   -*- Syntax: Common-Lisp; Package: USER; Base: 10; Mode: LISP -*-    ;;;
;;;                                                                       ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Implements a scaling operation to the current state.
;;; Allows for cleanly speeding up an entire rendering etc.
;;; Suggested by Jim Davis.
;;; This function uses a set of global scale factors initially set to
;;; unity.  They can be changed by the user to result in the entire
;;; reading being scaled. Will work with interruptions.
;;; { *table-of-final-scale-factors*
;;; Variable: *DEFAULT-FINAL-SCALE-FACTOR*                   Author: raman
;;; Created: Fri Aug 14 11:44:50 1992
;;; Variable: *TABLE-OF-FINAL-SCALE-FACTORS*                 Author: raman
;;; Created: Fri Aug 14 11:36:00 1992
;;; Function: DEFINE-FINAL-SCALE-FACTOR                      Author: raman
;;; Created: Fri Aug 14 11:37:43 1992
;;; Function: GET-FINAL-SCALE-FACTOR                         Author: raman
;;; Created: Fri Aug 14 11:38:46 1992
;;; Function: SET-FINAL-SCALE-FACTOR                         Author: raman
;;; Created: Fri Aug 14 11:40:44 1992
;;; }
;;; Relies on the list representation of point-in-speech-space 
;;; Function: SCALE-POINT-IN-SPEECH-SPACE                    Author: raman
;;; Created: Fri Aug 14 11:47:08 1992
      ;;; no sense in scaling voice:
;;; Function: SCALE-DIMENSION                                Author: raman
;;; Created: Fri Aug 14 11:51:21 1992
